package com.kevin.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * 树枝节点
 *
 * @author kevin
 * @date 2025/8/22
 */
public class Composite implements Component {

    private List<Component> childList = new ArrayList<>();

    @Override
    public void operation() {
        for (Component child : childList) {
            child.operation();
        }
    }

    @Override
    public void add(Component component) {
        childList.add(component);
    }

    @Override
    public void remove(Component component) {
        childList.remove(component);
    }

    @Override
    public Component getChild(int index) {
        return childList.get(index);
    }
}
